package com.nf.health.app.adapter;

import java.util.Map;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.nf.health.app.R;
import com.nf.health.app.models.EvaluationQuestion;

public class EvaluationQuestionAdapter extends BaseAdapter {

	private Context context;
	private EvaluationQuestion question;
	private Map<Integer, Boolean> isChecked;
	public EvaluationQuestionAdapter(Context context, EvaluationQuestion question, Map<Integer, Boolean> isChecked) {
		this.context = context;
		this.question = question;
		this.isChecked = isChecked;
	}
	@Override
	public int getCount() {
		if(question != null){
			return question.getAnswer().size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return question.getAnswer().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup group) {
		ViewHolder holder;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.item_evaluation_answer, null);
			holder.contentCB = (CheckBox) convertView.findViewById(R.id.tv_title);
			holder.layout_onclickView = (LinearLayout) convertView.findViewById(R.id.layout_onclickView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.contentCB.setText(question.getAnswerList().get(position).getValue());
		try {
			if(isChecked!=null && isChecked.get(position)){
				holder.contentCB.setChecked(true);
			}else{
				holder.contentCB.setChecked(false);
			}
		} catch (Exception e) {
		}
		return convertView;
	}
	class ViewHolder {
		CheckBox contentCB;
		LinearLayout layout_onclickView;
	}
	
}
